package net.yyge.manifest.editor.tag;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ManifestTag extends XmlTag {
    private Map<String,String> data = new HashMap<>();
    private Element element;
    private List<String> packages =new ArrayList<>();

    public ManifestTag(Element element) {
        this.element = element;
        NamedNodeMap attrMap = element.getAttributes();
        putData(attrMap,data);

        String packageName = data.get("package");
        packages.add(packageName);
    }

    public ManifestTag setValue(String attrName,String value){
        setValue(element,attrName,value);
        return this;
    }
    public ManifestTag addAttr(String attrName,String value){
        addAttribute(element,attrName,value);
        return this;
    }
    public ManifestTag setPackage(String packageName){
        setValue("package",packageName);
        data.put("package",packageName);
         packages.add(packageName);
        return this;
    }

    public String getPackage(){
        return data.get("package");
    }

    public String getOldPackageName(){
        if(packages.size()==1){
            return null;
        }
        return packages.get(packages.size()-2);
    }
}
